package com.team.controller;

import com.team.entity.Competition;
import com.team.service.CompetitionService;
import com.team.vo.CompetitionVo;
import com.team.vo.Result;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping
@RestController
@Slf4j
public class CompetitionController {
    @Autowired
    private CompetitionService competitionService;
    /**
     * 获得所有比赛
     * @return
     */
    @GetMapping("/getAllCompetitions")
    public Result<List<Competition>> getAllCompetitions(){
        return Result.success(competitionService.getAllCompetition());
    }

    /**
     * 获得某个比赛详情
     * @param cid
     * @param studentId
     * @return
     */
    @GetMapping("/getCompetition_details")
    public Result<Competition> getCompetitionDetails(String cid, @RequestParam("student_id") String studentId){
        return Result.success(competitionService.getCompetitionDetails(cid));
    }

    /**
     * 某个用户获得自己已经报名的比赛
     * @param studentId
     * @return
     */
    @GetMapping("/getMy_contest")
    public Result<List<CompetitionVo>> getMyContest(@RequestParam("student_id") int studentId){
        List<CompetitionVo> competitions=competitionService.getCompetitionsByStudentId(studentId);
        return Result.success(competitions);
    }
}
